<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Elasticsearch 分词器深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 24px;
            overflow-x: auto;
            position: relative;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .code-block::before {
            content: 'JSON';
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(255, 255, 255, 0.1);
            padding: 4px 12px;
            border-radius: 4px;
            font-size: 12px;
            color: #888;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
            transition: all 0.3s ease;
        }
        
        .feature-icon:hover {
            transform: rotate(10deg) scale(1.1);
        }
        
        .workflow-step {
            position: relative;
            padding-left: 40px;
            margin-bottom: 24px;
        }
        
        .workflow-step::before {
            content: attr(data-step);
            position: absolute;
            left: 0;
            top: 0;
            width: 30px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 14px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    Elasticsearch 分词器
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解文本处理的核心组件
                </p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-cut mr-2"></i>文本分析
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-search mr-2"></i>搜索优化
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-cogs mr-2"></i>自定义配置
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="max-w-5xl mx-auto mb-16">
            <div class="content-card rounded-2xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700" style="text-indent: 2em;">
                    Elasticsearch 中的分词器（Analyzer）是处理文本数据的重要组件，用于将文本数据拆分为有用的词项（tokens），这些词项在索引和搜索过程中发挥着关键作用。
                </p>
            </div>
        </div>

        <!-- Working Principle Section -->
        <div class="max-w-5xl mx-auto mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-microscope mr-3 text-purple-600"></i>分词器的工作原理
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <!-- Character Filters -->
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-filter"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">字符过滤器</h3>
                    <p class="text-gray-600 mb-4">在分词之前对原始文本进行预处理。常见的操作包括去除HTML标签、替换字符等。</p>
                    <div class="bg-gray-100 rounded-lg p-3">
                        <code class="text-sm text-purple-600">html_strip</code>
                        <p class="text-xs text-gray-500 mt-1">去除 HTML 标签</p>
                    </div>
                </div>

                <!-- Tokenizers -->
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-cut"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">分词器</h3>
                    <p class="text-gray-600 mb-4">将文本拆分成一个个词项（tokens）。每个词项是文本索引的基本单元。</p>
                    <div class="bg-gray-100 rounded-lg p-3">
                        <code class="text-sm text-purple-600">standard</code>
                        <p class="text-xs text-gray-500 mt-1">按空格和标点符号拆分</p>
                    </div>
                </div>

                <!-- Token Filters -->
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-magic"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">词项过滤器</h3>
                    <p class="text-gray-600 mb-4">对分词后的词项进行进一步处理，如转换大小写、去除停用词、词干提取等。</p>
                    <div class="bg-gray-100 rounded-lg p-3">
                        <code class="text-sm text-purple-600">lowercase</code>
                        <p class="text-xs text-gray-500 mt-1">转换为小写</p>
                    </div>
                </div>
            </div>

            <!-- Workflow Example -->
            <div class="content-card rounded-xl p-8">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-project-diagram mr-2 text-purple-600"></i>工作流程示例
                </h3>
                
                <div class="highlight-box">
                    <p class="text-gray-700 mb-4">
                        假设输入文本为 <code class="bg-gray-200 px-2 py-1 rounded">"Hello World!"</code>
                    </p>
                    
                    <div class="space-y-4">
                        <div class="workflow-step" data-step="1">
                            <h4 class="font-semibold text-gray-800">原始输入</h4>
                            <p class="text-gray-600">"Hello World!"</p>
                        </div>
                        
                        <div class="workflow-step" data-step="2">
                            <h4 class="font-semibold text-gray-800">Standard 分词器处理</h4>
                            <p class="text-gray-600">["Hello", "World"]</p>
                        </div>
                        
                        <div class="workflow-step" data-step="3">
                            <h4 class="font-semibold text-gray-800">Lowercase 过滤器处理</h4>
                            <p class="text-gray-600">["hello", "world"]</p>
                        </div>
                    </div>
                </div>

                <!-- Mermaid Diagram -->
                <div class="mermaid">
                    graph LR
                        A[原始文本] --> B[字符过滤器]
                        B --> C[分词器]
                        C --> D[词项过滤器]
                        D --> E[最终词项]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style E fill:#9f9,stroke:#333,stroke-width:2px
                        style B fill:#bbf,stroke:#333,stroke-width:2px
                        style C fill:#fbf,stroke:#333,stroke-width:2px
                        style D fill:#ffb,stroke:#333,stroke-width:2px
                </div>
            </div>
        </div>

        <!-- Custom Analyzer Section -->
        <div class="max-w-5xl mx-auto mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-tools mr-3 text-purple-600"></i>自定义分词器
            </h2>

            <div class="content-card rounded-xl p-8 mb-8">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">创建自定义分词器</h3>
                <p class="text-gray-700 mb-6">
                    通过组合不同的字符过滤器、分词器和词项过滤器来满足特定需求。以下是一个完整的配置示例：
                </p>
                
                <div class="code-block">
                    <pre><code>{
  "settings": {
    "analysis": {
      "char_filter": {
        "my_html_strip": {
          "type": "html_strip"
        }
      },
      "tokenizer": {
        "my_whitespace": {
          "type": "whitespace"
        }
      },
      "filter": {
        "my_lowercase": {
          "type": "lowercase"
        },
        "my_stop": {
          "type": "stop",
          "stopwords": ["the", "is"]
        